<template>
	<view>
		<view class="navigation">
			<view class="navigation_back" @tap="backref()">
				<uni-icons type="back" size="24" color="#fff"></uni-icons>
			</view>
			<view class="navigation_title">
				添加地址
			</view>
		</view>
		<view class="address_con">
			<view class="address_item address_name">
				<view class="address_icon">
					<!-- <image src="../../../static/image/memberCenter/address_name.svg" mode=""></image> -->
					姓名
				</view>
				<view class="address_input">
					<input type="text" v-model="address.userName" placeholder="请输入您的姓名" placeholder-class="placeholder">
				</view>
			</view>
			<view class="address_item address_phone">
				<view class="address_icon">
					<!-- <image src="../../../static/image/memberCenter/address_phone.svg" mode=""></image> -->
					电话
				</view>
				<view class="address_input">
					<input type="text" v-model="address.userPhone" placeholder="请输入电话号码">
				</view>
			</view>
			<!-- <view class="address_item address_location">
				<view class="address_icon">
					<image src="../../../static/image/memberCenter/address_location.svg" mode=""></image>
				</view>
				<view class="address_input">
					<input type="text" placeholder="请选择地址">
				</view>
				<view class="address_more">
					<uni-icons type="forward" size="16"></uni-icons>
				</view>
			</view> -->
			<view class="address_item address_building">
				<view class="address_icon">
					<!-- <image src="../../../static/image/memberCenter/address_build.svg" mode=""></image> -->
					寝室
				</view>
				<view class="address_input">
					<radio-group  @change="setOptions">
						<label>
							<radio value="男寝" :checked="add.sex == '男寝'" /><text>男寝</text>
						</label>
						<label>
							<radio value="女寝" :checked="add.sex == '女寝'" /><text>女寝</text>
						</label>
					</radio-group>
					<!-- <input v-model="address.userAddress"  type="text" placeholder="请填写详细地址"> -->
				</view>
			</view>
			<view class="address_item address_plate">
				<view class="address_icon">
					<!-- <image src="../../../static/image/memberCenter/address_plate.svg" mode=""></image> -->
					楼栋
				</view>
				<view class="address_input">
					<input type="text" v-model="add.build" placeholder="请输入楼栋号">
				</view>
			</view>
			<view class="address_item address_plate">
				<view class="address_icon">
					<!-- <image src="../../../static/image/memberCenter/address_plate.svg" mode=""></image> -->
					详细地址
				</view>
				<view class="address_input">
					<input type="text" v-model="add.detail" placeholder="请输入寝室号">
				</view>
			</view>
			<view class="address_item address_default">
				<view class="address_item_label">
					设为默认收货地址
				</view>
				<label class="radio"><radio checked="true" color="#2588FF"/></label>
			</view>
			
			<view class="address_add" @tap="sureAddress()">
				<view style="padding: 0 24rpx;">
					<button>确定</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { addAddress } from '../../../api/api.js'
	export default {
		data() {
			return {
				address: {
				    // userId:uni.getStorageSync('token'),
				    userName:'',
				    userPhone:'',
				    userAddress:'',
				    isDefault:'1'
				},
				add: {
					sex: '男寝',
					build:'',
					detail:''
				}
			};
		},
		methods:{
			setOptions(e) {
				this.add.sex = e.detail.value
			},
			backref() {
				uni.navigateBack({
					delta: 1
				})
			},
			sureAddress(){
				if (!this.address.userName) {
					uni.showToast({
					    icon: 'none',   
					    duration: 3000,
					    title: '请填写姓名'
					});
					return
				}if (!this.address.userPhone) {
					uni.showToast({
					    icon: 'none',   
					    duration: 3000,
					    title: '请填写手机号码'
					});
					return
				}
				if (!this.add.build) {
					uni.showToast({
					    icon: 'none',   
					    duration: 3000,
					    title: '请填写楼栋号'
					});
					return
				}
				if (!this.add.detail) {
					uni.showToast({
					    icon: 'none',   
					    duration: 3000,
					    title: '请填写寝室号'
					});
					return
				}
				this.address.userAddress = this.add.sex + ' ' + this.add.build + ' ' + this.add.detail
				console.log(this.address)
				uni.showLoading()
				addAddress(this.address).then(res => {
					if (res.code == 200) {
						uni.showToast({
						    icon: 'none',   
						    duration: 3000,
						    title: res.msg
						});
						uni.hideLoading()
						uni.navigateBack({
							delta: 1
						})
					}
				})
				// uni.navigateTo({
				// 	url:'/pages/memberCenter/address/address'
				// })
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F4F4F4;
	}

	.navigation {
		width: 100%;
		height: 260rpx;
		background: linear-gradient(180deg, rgba(255, 141, 26, 1) 12.5%, rgba(255, 195, 0, 1) 100%);
		padding: 60rpx 24rpx 0;
		text-align: center;
		position: relative;

		.navigation_back {
			position: absolute;
			top: 60rpx;
		}

		.navigation_title {
			color: #fff;
			font-size: 36rpx;
		}
	}
	.address_con{
		position: relative;
		z-index: 2;
		padding: 40rpx 32rpx 180rpx;
		border-radius: 32rpx 32rpx 0 0;
		background-color: #F4F4F4;
		margin-top: -100rpx;
		
		.address_item{
			position: relative;
			display: flex;
			align-items: center;
			height: 100rpx;
			background-color: #fff;
			border-radius: 12rpx;
			margin-bottom: 24rpx;
			padding: 0 24rpx;
			.address_icon{
				// width: 40rpx;
				display: flex;
				justify-content: center;
				image{
					width: 40rpx;
					height: 42rpx;
				}
			}
			.address_input{
				margin-left: 30rpx;
				input{
					color: #333;
					font-size: 26rpx;
					width: 400rpx;
					&.placeholder{
						color: #666;
					}
				}
			}
			.address_more{
				position: absolute;
				right: 24rpx;
			}
			.address_item_label{
				font-size: 30rpx;
				color: #2E343A;
			}
			.radio{
				position: absolute;
				right: 24rpx;
			}
		}
	}
	.address_add {
		position: fixed;
		left: 0;
		bottom: 50rpx;
		width: 100%;
		// padding: 0 24rpx;
	
		button {
			height: 80rpx;
			background: linear-gradient(180deg, rgba(255, 141, 26, 1) 12.5%, rgba(255, 195, 0, 1) 100%);
			color: #fff;
			font-size: 28rpx;
			font-weight: 700;
			border: 0;
			line-height: 80rpx;
			border-radius: 80rpx;
		}
	}
</style>
